import 'package:flutter/material.dart';
import 'package:flutter_country_website/model/Product.dart';

class GoodsDetail extends StatefulWidget {
  GoodsDetail({
    Key? key,
    required this.product
  }) : super(key: key);

  final Product product;

  @override
  State<GoodsDetail> createState() => _GoodsDetailState();
}

class _GoodsDetailState extends State<GoodsDetail> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // appBar: appBar('商品详情'),
      body: SafeArea(
        child: content()
      )
    );
  }

  Widget content() {
    return SingleChildScrollView(
        child: Column(
          children: [
            Stack(
              children: [
                Container(
                  width: double.maxFinite,
                  height: 300,
                  child: Image.network(widget.product.image!, fit: BoxFit.fill),
                ),
                Positioned(
                  right: 0,
                  bottom: 0,
                  child: Text("学号 + 姓名", style: TextStyle(fontSize: 16))
                )
              ],
            ),
            Container(
              margin: EdgeInsets.only(left: 10, right: 10, top: 10),
              child: Row(
                children: [
                  Expanded(
                      child: Text(widget.product.name!, style: TextStyle(fontWeight: FontWeight.bold))
                  )
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.only(left: 10, right: 10, top: 10),
              child: Column(
                children: [
                  Row(
                    children: [
                      Text('评分: '),
                      stars()
                    ],
                  ),
                  SizedBox(height: 10),
                  Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text('热门评价: '),
                      Expanded(
                        child: Text(widget.product.evaluate!)
                      )
                    ],
                  )
                ],
              ),
            )
          ],
        )
    );
  }

  Widget stars() {
    return Row(
      mainAxisSize: MainAxisSize.min,
      children: [
        Icon(Icons.star, size: 20, color: Colors.amber),
        Icon(Icons.star, size: 20, color: Colors.amber),
        Icon(Icons.star, size: 20, color: Colors.amber),
        Icon(Icons.star, size: 20, color: Colors.amber),
        Icon(Icons.star, size: 20, color: Colors.amber)
      ],
    );
  }
}
